package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.impl.SetmealServiceImpl;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.logging.log4j.message.ReusableMessage;
import org.springframework.data.repository.query.Param;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/setmeal")
@Slf4j
@Api(tags = "套餐相关接口")
public class SetmealController {
    private final SetmealServiceImpl setmealServiceImpl;

    public SetmealController(SetmealServiceImpl setmealServiceImpl) {
        this.setmealServiceImpl = setmealServiceImpl;
    }

    @PostMapping
    @ApiOperation("新增套餐")
    public Result save(@RequestBody SetmealDTO setmealDTO){
        log.info("新增套餐 {} ",setmealDTO);
        setmealServiceImpl.saveWithDish(setmealDTO);
        return Result.success();
    }
    //套餐分页查询
    @ApiOperation("套餐分页查询")
    @GetMapping("/page")
    public Result<PageResult> page( SetmealPageQueryDTO setmealPageQueryDTO){
        log.info("分页查询{}",setmealPageQueryDTO);

        PageResult pageResult = setmealServiceImpl.PageQuery(setmealPageQueryDTO);
        return Result.success(pageResult);
    }
    @ApiOperation("修改套餐状态")
    @PostMapping("/status/{status}")
    public Result startOrStop(@PathVariable Integer status,Long id){
        log.info("修改套餐状态{}",id);
        setmealServiceImpl.startOrStop(status,id);
        return Result.success();
    }
    @ApiOperation("查询套餐")
    @GetMapping("/{id}")
    public Result<SetmealVO> getById(@PathVariable Long id){
        log.info("查询套餐{}",id);
        SetmealVO setmealVO = setmealServiceImpl.getById(id);
        return Result.success(setmealVO);
    }
    @ApiOperation("修改套餐")
    @PutMapping
    public Result update(@RequestBody SetmealDTO setmealDTO){
        log.info("修改套餐{}",setmealDTO);
        setmealServiceImpl.update(setmealDTO);
        return Result.success();
    }
    @ApiOperation("删除套餐")
    @DeleteMapping
    public Result delete(@RequestParam List<Long> ids){
        log.info("删除套餐{}",ids);
        setmealServiceImpl.delete(ids);
        return Result.success();
    }
}
